package com.developer.platform.infrastructure.security.handler;

import com.veeker.core.exceptions.BusinessException;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 异常处理
 *
 * @author ：qiaoliang
 * @date ：2020-10-19
 */
public class ErrorHandler {

    public static void forward(HttpServletRequest request, HttpServletResponse response ,
                                            BusinessException businessException) throws ServletException, IOException {
        // 异常捕获，发送到error controller
        request.setAttribute("error", businessException);
        //将异常分发到/errors控制器
        request.getRequestDispatcher("/api/error").forward(request, response);
    }

}
